package com.ufenlei.LTS {
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.TextEvent;

	/**
	 * @author bbn
	 */
	public class TestingLibItem extends MovieClip {
		public var url:String;
		private var isOpen:Boolean = false;
		private var ftime:int;
		private var mtime:int;
		private var wtime:int;
		private var ascore:Number;
		public function TestingLibItem(title:String,
										testingURL:String,
										date:String = "",
										fulltime:int = 0, 
										monthtime:int = 0,
										weektime:int = 0,
										averageScore:Number = 0) {
			titleF.text = title;
			dateF.text = date;
			ftime = fulltime;
			mtime = monthtime;
			wtime = weektime;
			ascore = averageScore;
			url = testingURL;
			this.gotoAndStop("closed");
			beginBtn.addEventListener(Input.CLICK,onStartClick);
			beginBtn.text = "Start";
			var detailField:TextField = detail;
			var tf:TextFormat = new TextFormat();
			tf.url = "event:detail";
			detailField.setTextFormat(tf);
			detailField.addEventListener(TextEvent.LINK, onLinkHandle);
		}
		public function fillDetail():void {
			field1.text = "完成次数："+ ftime;
			field2.text = "本月完成："+ mtime;
			field3.text = "本周完成："+ wtime;
			field4.text = "平均分数："+ ascore;
		}
		private function onStartClick(evt:Event):void{
			this.dispatchEvent(new Event(Input.CLICK,true));
		}
		private function onLinkHandle(evt:TextEvent):void{
			trace(evt.text);
			if(evt.text == "detail"){
				toggleDetail();
			}
		}
		private function toggleDetail():void{
			trace("toggleDetail()1",isOpen);
			isOpen?this.gotoAndStop("closed"):this.gotoAndStop("opened");
			isOpen = !isOpen;
			trace("toggleDetail()2",isOpen);
			if(isOpen){
				fillDetail();
			}
			this.dispatchEvent(new Event(Input.CHANGE));
		};
	}
}
